/*
* Copyright (c)  2017, ueboot.com
* All rights reserved.
* 2017-10-12 20:48:38
*/
package com.ueboot.weishop.service.setting.impl;

import com.ueboot.core.repository.BaseRepository;
import com.ueboot.core.service.impl.BaseServiceImpl;
import com.ueboot.weishop.entity.setting.AttrOptionValueEntity;
import com.ueboot.weishop.entity.setting.AttributeEntity;
import com.ueboot.weishop.repository.setting.AttrOptionValueRepository;
import com.ueboot.weishop.service.setting.AttrOptionValueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yangkui  on 2017-10-12 20:48:38.
 *
 * @since 2.0 by autocode
 */
@Slf4j
@Service
public class AttrOptionValueServiceImpl extends BaseServiceImpl<AttrOptionValueEntity> implements AttrOptionValueService{
    @Autowired
    private AttrOptionValueRepository attrOptionValueRepository;

    @Override
    protected BaseRepository getBaseRepository() {
         return attrOptionValueRepository;
    }

    @Override
    public Page<AttrOptionValueEntity> findByAttrId(Pageable pageable, Long attrId) {
        AttrOptionValueEntity entity = new AttrOptionValueEntity();
        AttributeEntity attr = new AttributeEntity();
        attr.setId(attrId);
        entity.setAttr(attr);
        ExampleMatcher matcher = ExampleMatcher.matching().withIgnoreNullValues()
                .withMatcher("attr.id",matcher1 -> matcher1.exact());
        return attrOptionValueRepository.findAll(Example.of(entity,matcher),pageable);
    }

    @Override
    public List<AttrOptionValueEntity> findByAttrId(Long attrId) {
        return attrOptionValueRepository.findByAttrId(attrId);
    }
}
